﻿package baidu.reader.common.model
{
    import baidu.ui.managers.*;
    import flash.events.*;
    import flash.net.*;

    public class TocRemoteDataProxy extends EventDispatcher
    {
        private var tocLoader:URLLoader;
        private var _xmlData:XML;

        public function TocRemoteDataProxy(param1:IEventDispatcher = null)
        {
            this.tocLoader = new URLLoader();
            super(param1);
            return;
        }// end function

        public function getXMLData() : void
        {
            this.tocLoader.addEventListener(Event.COMPLETE, this.tocLoadCompleteHandler);
            this.tocLoader.addEventListener(IOErrorEvent.IO_ERROR, this.tocLoadErrorHandler);
            this.tocLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.tocLoadErrorHandler);
            var _loc_1:* = (InstanceManager.createSingletonInstance(AppConfigModel) as AppConfigModel).getTocURL();
            this.tocLoader.load(new URLRequest(_loc_1));
            return;
        }// end function

        private function tocLoadErrorHandler(event:Event) : void
        {
            dispatchEvent(new ErrorEvent(ErrorEvent.ERROR));
            return;
        }// end function

        private function tocLoadCompleteHandler(event:Event) : void
        {
            var tmpXML:XML;
            var event:* = event;
            try
            {
                tmpXML = new XML(this.tocLoader.data);
            }
            catch (e:Error)
            {
            }
            if (tmpXML)
            {
                this._xmlData = tmpXML;
                dispatchEvent(event);
                return;
            }
            dispatchEvent(new ErrorEvent(ErrorEvent.ERROR));
            return;
        }// end function

        public function get xmlData() : XML
        {
            return this._xmlData;
        }// end function

    }
}
